/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmConjunto.java
 *
 * Created on 03-dic-2014, 9:48:32
 */
package presentacion;

import Negocio.Entero;
import Negocio.VectorEntero;
import javax.swing.table.DefaultTableModel;
import javax.swing.JTable;
/**
 *
 * @author TOSHIBA
 */
public class FrmConjunto extends javax.swing.JFrame {

    /** Creates new form FrmConjunto */
    public FrmConjunto() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        dtvA = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        dtvU = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        CargarAB = new javax.swing.JButton();
        CargarA = new javax.swing.JButton();
        CargarB = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        dtvB = new javax.swing.JTable();
        CargarInterseccion = new javax.swing.JButton();
        CargarA_B = new javax.swing.JButton();
        txDimension = new javax.swing.JTextField();
        txDimension1 = new javax.swing.JTextField();
        CargarB_A = new javax.swing.JButton();
        CargarB_A1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        dtvA.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(dtvA);

        jLabel1.setText("CONJUNTO A");

        dtvU.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(dtvU);

        jLabel2.setText("CONJUNTO B");

        CargarAB.setText("UNION");
        CargarAB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CargarABActionPerformed(evt);
            }
        });

        CargarA.setText("CARGAR");
        CargarA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CargarAActionPerformed(evt);
            }
        });

        CargarB.setText("CARGAR");
        CargarB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CargarBActionPerformed(evt);
            }
        });

        dtvB.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(dtvB);

        CargarInterseccion.setText("INTERSECCION");
        CargarInterseccion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CargarInterseccionActionPerformed(evt);
            }
        });

        CargarA_B.setText("A - B");
        CargarA_B.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CargarA_BActionPerformed(evt);
            }
        });

        CargarB_A.setText("B - A");
        CargarB_A.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CargarB_AActionPerformed(evt);
            }
        });

        CargarB_A1.setText("DIF SIMETRICA");
        CargarB_A1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CargarB_A1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(CargarAB)
                        .addGap(18, 18, 18)
                        .addComponent(CargarInterseccion)
                        .addGap(18, 18, 18)
                        .addComponent(CargarA_B)
                        .addGap(18, 18, 18)
                        .addComponent(CargarB_A)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CargarB_A1)
                        .addContainerGap(207, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 3, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(txDimension, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(24, 24, 24)
                                        .addComponent(CargarA))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel2)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(txDimension1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(26, 26, 26)
                                        .addComponent(CargarB))
                                    .addComponent(jScrollPane3)
                                    .addComponent(jScrollPane1))))
                        .addGap(201, 201, 201))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(CargarA)
                    .addComponent(txDimension, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(CargarB)
                    .addComponent(txDimension1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CargarAB)
                    .addComponent(CargarInterseccion)
                    .addComponent(CargarA_B)
                    .addComponent(CargarB_A)
                    .addComponent(CargarB_A1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    private void Dimensionar(int CantidadColumna, JTable dtv)
{
    DefaultTableModel modelo = new DefaultTableModel();
    dtv.setModel(modelo);
    for(int i = 0; i <= CantidadColumna-1; i++)
    {
        modelo.addColumn(Integer.toString(i));
    }
    Object[] fila = new Object[1];
    modelo.addRow(fila);
}
    
private void CargarConjunto (Negocio.Conjunto ObjVector, JTable dtv, int dimen)
{
    for (int i = 0; i <= (dimen)-1; i++)
    {
        Entero objEntero = new Entero();
        objEntero.setNum(Integer.parseInt(dtv.getValueAt(0, i).toString()));
        ObjVector.Insertar(objEntero);
    }    
}

private void MostrarConjunto(Negocio.Conjunto Objc, JTable dtv)
    {
        for (int i = 0; i <= Objc.getN()-1; i++)
        {
        dtv.setValueAt(Objc.LeerVector(i).getNum(), 0, i);        
        } 
    }
    
private void CargarAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CargarAActionPerformed
     this.Dimensionar(Integer.parseInt(this.txDimension.getText()), dtvA);
}//GEN-LAST:event_CargarAActionPerformed

private void CargarBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CargarBActionPerformed
// TODO add your handling code here:
     this.Dimensionar(Integer.parseInt(this.txDimension1.getText()),dtvB);
}//GEN-LAST:event_CargarBActionPerformed

Negocio.Conjunto objCon = new Negocio.Conjunto();


private void CargarABActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CargarABActionPerformed
// TODO add your handling code her
    
    Negocio.Conjunto conjA = new Negocio.Conjunto();
    Negocio.Conjunto conjB = new Negocio.Conjunto();
    Negocio.Conjunto conjU = new Negocio.Conjunto();
    this.CargarConjunto(conjA,dtvA,Integer.parseInt(this.txDimension.getText()));
    this.CargarConjunto(conjB,dtvB,Integer.parseInt(this.txDimension1.getText()));
    conjU = conjA.Union(conjA, conjB);
    this.Dimensionar(conjU.getN() , dtvU);
    this.MostrarConjunto(conjU,dtvU);
   
}//GEN-LAST:event_CargarABActionPerformed

private void CargarInterseccionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CargarInterseccionActionPerformed
// TODO add your handling code here:
    Negocio.Conjunto conjA = new Negocio.Conjunto();
    Negocio.Conjunto conjB = new Negocio.Conjunto();
    Negocio.Conjunto conjU = new Negocio.Conjunto();
    this.CargarConjunto(conjA,dtvA,Integer.parseInt(this.txDimension.getText()));
    this.CargarConjunto(conjB,dtvB,Integer.parseInt(this.txDimension1.getText()));
    conjU = conjA.Interseccion(conjA, conjB);
    this.Dimensionar(conjU.getN() , dtvU);
    this.MostrarConjunto(conjU,dtvU);
}//GEN-LAST:event_CargarInterseccionActionPerformed

private void CargarA_BActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CargarA_BActionPerformed
// TODO add your handling code here:
    Negocio.Conjunto conjA = new Negocio.Conjunto();
    Negocio.Conjunto conjB = new Negocio.Conjunto();
    Negocio.Conjunto conjU = new Negocio.Conjunto();
    this.CargarConjunto(conjA,dtvA,Integer.parseInt(this.txDimension.getText()));
    this.CargarConjunto(conjB,dtvB,Integer.parseInt(this.txDimension1.getText()));
    conjU = conjA.A_menos_B(conjA, conjB);
    this.Dimensionar(conjU.getN() , dtvU);
    this.MostrarConjunto(conjU,dtvU);
}//GEN-LAST:event_CargarA_BActionPerformed

private void CargarB_AActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CargarB_AActionPerformed
// TODO add your handling code here:
    Negocio.Conjunto conjA = new Negocio.Conjunto();
    Negocio.Conjunto conjB = new Negocio.Conjunto();
    Negocio.Conjunto conjU = new Negocio.Conjunto();
    this.CargarConjunto(conjA,dtvA,Integer.parseInt(this.txDimension.getText()));
    this.CargarConjunto(conjB,dtvB,Integer.parseInt(this.txDimension1.getText()));
    conjU = conjA.B_menos_A(conjA, conjB);
    this.Dimensionar(conjU.getN() , dtvU);
    this.MostrarConjunto(conjU,dtvU);
}//GEN-LAST:event_CargarB_AActionPerformed

private void CargarB_A1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CargarB_A1ActionPerformed
// TODO add your handling code here:
    Negocio.Conjunto conjA = new Negocio.Conjunto();
    Negocio.Conjunto conjB = new Negocio.Conjunto();
    Negocio.Conjunto conjU = new Negocio.Conjunto();
    Negocio.Conjunto conjAB = new Negocio.Conjunto();
    Negocio.Conjunto conjBA = new Negocio.Conjunto();
    this.CargarConjunto(conjA,dtvA,Integer.parseInt(this.txDimension.getText()));
    this.CargarConjunto(conjB,dtvB,Integer.parseInt(this.txDimension1.getText()));
    conjBA = conjA.B_menos_A(conjA, conjB);
    conjAB = conjA.A_menos_B(conjA, conjB);
    conjU  = conjU.Union(conjAB, conjBA);
    this.Dimensionar(conjU.getN() , dtvU);
    this.MostrarConjunto(conjU,dtvU);
}//GEN-LAST:event_CargarB_A1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmConjunto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmConjunto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmConjunto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmConjunto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FrmConjunto().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CargarA;
    private javax.swing.JButton CargarAB;
    private javax.swing.JButton CargarA_B;
    private javax.swing.JButton CargarB;
    private javax.swing.JButton CargarB_A;
    private javax.swing.JButton CargarB_A1;
    private javax.swing.JButton CargarInterseccion;
    private javax.swing.JTable dtvA;
    private javax.swing.JTable dtvB;
    private javax.swing.JTable dtvU;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextField txDimension;
    private javax.swing.JTextField txDimension1;
    // End of variables declaration//GEN-END:variables
}
